// 领用记录
<template>
  <yd-layout>
    <yd-navbar slot="navbar" title="领用记录" bgcolor="#0a0a0a" color="#fff">
      <router-link to="/beautician/stock" slot="left">
        <yd-navbar-back-icon color="#fff"></yd-navbar-back-icon>
      </router-link>
    </yd-navbar>
    <yd-infinitescroll :callback="loadmore" ref="infinitescroll">
      <div slot="list" style="padding-top:5px;">
        <div v-for="(item, i) in list" :key="i" class="staff-list-item">
          <div class="name">
            {{item.pname}}
          </div>
          <div class="spec">
            {{item.count}}{{item.pSpec}}
            {{item.numSpec}}{{item.spec}}
          </div>
          <div class="time">
            {{getFormarDateStr(item.createtime)}}
          </div>
        </div>
      </div>
      <img slot="loadingTip" src="http://static.ydcss.com/uploads/ydui/loading/loading10.svg"/>
      <span slot="doneTip">无数据</span>
    </yd-infinitescroll>

  </yd-layout>
</template>

<script>
import pageMixin from "../../../../mixins/page";
export default {
  mixins: [pageMixin],
  props: {
    pid: {},
  },
  data() {
    return {
      pagination: {
        rows: 10,
        page: 1,
      },
      list: [],
    };
  },
  computed: {
    uid() {
      return this.$store.state.uid;
    },
  },
  methods: {
    async loadmore() {
      let res = await this.loadData().catch(err => {});

      if (res.rows.length < this.pagination.rows) {
        this.$refs["infinitescroll"].$emit("ydui.infinitescroll.loadedDone");
      } else {
        this.$refs["infinitescroll"].$emit("ydui.infinitescroll.finishLoad");
      }
    },
    getFormarDateStr(timestamp) {
      if (!timestamp) return "--";
      return new Date(timestamp * 1000).$formatStr("yyyy-MM-dd hh:mm:ss");
    },
    async loadData() {
      return new Promise(async (resolve, reject) => {
        let res = await this.$api
          .searchStaffStocks({
            pid: this.pid,
            fid: this.uid,
            rows: this.pagination.rows,
            page: this.pagination.page,
          })
          .catch(err => {
            reject(err);
          });

        if (res) {
          this.total = res.total;
          this.list = this.list.concat(res.rows);
          resolve(res);
        } else {
          reject();
        }
      });
    },
    async init() {
      this.indicator = true;
      await this.loadData();
      this.indicator = false;
    },
  },
  created() {
    this.init();
  },
};
</script>

<style>
</style>
